﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Threading;

namespace Conqueror.WP
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            //Clear back stack. This page is only ever navigated to after login. Clear all back history.
            while (NavigationService.CanGoBack)
                NavigationService.RemoveBackEntry();

            base.OnNavigatedTo(e);
        }

        private void DisplayPlayerCard(object sender, GestureEventArgs e)
        {
            if (!(radTransitionControl.Content is View.SelectedUserCard))
                radTransitionControl.Content = new View.SelectedUserCard();
        }

        private void DisplayGameCard(object sender, GestureEventArgs e)
        {
            var game = new View.SelectedGameCard();
            game.DataContext = (sender as FrameworkElement).DataContext;

            if (!(radTransitionControl.Content is View.SelectedGameCard && game.DataContext == ((View.SelectedGameCard)radTransitionControl.Content).DataContext))
                radTransitionControl.Content = game;
        }

        private void DisplaySettingsPage(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
        }

        private void DisplayMatchmakingPage(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MatchmakingPage.xaml", UriKind.Relative));
        }

        private void DisplayWebsite(object sender, GestureEventArgs e)
        {
            var task = new Microsoft.Phone.Tasks.WebBrowserTask();
            task.Uri = new Uri("http://www.conquerclub.com/", UriKind.Absolute);
            task.Show();
        }

        private void DisplayWiFiConnection(object sender, GestureEventArgs e)
        {
            var task = new Microsoft.Phone.Tasks.ConnectionSettingsTask();
            task.ConnectionSettingsType = Microsoft.Phone.Tasks.ConnectionSettingsType.WiFi;
            task.Show();
        }

        private void DisplayCellular(object sender, GestureEventArgs e)
        {
            var task = new Microsoft.Phone.Tasks.ConnectionSettingsTask();
            task.ConnectionSettingsType = Microsoft.Phone.Tasks.ConnectionSettingsType.Cellular;
            task.Show();
        }
    }
}
